package com.gagakuai.bpm.busniess.run;


import com.gagakuai.bpm.domian.dto.response.ResponseStatusDto;
import com.gagakuai.bpm.domian.events.CallBusinessStartProcessEvent;
import com.gagakuai.bpm.rpcservice.openfeign.UserHttpApi;
import com.gagakuai.bpm.utils.StringUtils;
import com.gagakuai.bpm.utils.UserUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class CallBusinessStartProcessRun implements Runnable{

    private CallBusinessStartProcessEvent event;

    @Resource
    private UserHttpApi userHttpApi;

    public void setEvent(CallBusinessStartProcessEvent event) {
        this.event = event;
    }

    @Override
    public void run() {
        if(StringUtils.isBlank(event.getBusinessId())  || ObjectUtils.isEmpty(event.getSubBusinessIdAndProcInstId())){
            return;
        }
        UserUtil.setToken(event.getToken());
        ResponseStatusDto<Void> responseStatusDto = userHttpApi.backStartSubProcInfo(event.getBusinessId(), event.getSubBusinessIdAndProcInstId());
        UserUtil.removeToken();
        if(responseStatusDto.isSuccess()){
            log.info("启动流程后回调接口成功");
        }else{
            log.info("启动流程后回调接口失败");
        }
    }
}
